﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace blog.Class
{
    public class PageBase : System.Web.UI.Page
    {
        protected string username;
        protected string password;



        protected void PageBase_Load(object sender, EventArgs e)
        {
            HttpCookie thecookie = HttpContext.Current.Request.Cookies["user"];
            if (thecookie != null)
            {
                this.username = thecookie.Values["username"].ToString();
                this.password = thecookie.Values["password"].ToString();
            }
            else if (Session["username"] != null)
            {
                username = Session["username"].ToString();
                password = Session["password"].ToString();
            }
            else
                Response.Redirect("../ErrorPage.aspx?error=TIMEOUT");
        }

        public bool islogin()
        {
            HttpCookie thecookie = HttpContext.Current.Request.Cookies["user"];
            if (thecookie != null)
            {

                return true;
            }
            else if (Session["username"] != null)
            {

                return true;
            }
            else
                return false;


        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.Load += new System.EventHandler(this.PageBase_Load);
        }


        #region [Alert]
        public virtual void Alert(string strWaring_Message)
        {
            System.Web.UI.WebControls.Literal li = new System.Web.UI.WebControls.Literal();
            li.Text = @"<Script lauguage='JavaScript'>alert('" + strWaring_Message + "');</script>";
            Page.Controls.Add(li);
        }

        public void Alert(UpdatePanel panel, String strWaring_Message)
        {
            ScriptManager.RegisterStartupScript(panel, this.GetType(), "update", "alert('" + strWaring_Message + "');", true);
        }

        public void Alert(Page page, String strWaring_Message)
        {
            ScriptManager.RegisterStartupScript(page, this.GetType(), "login", "alert('" + strWaring_Message + "');", true);
        }
        #endregion

    }
}
